/*
 * Title: WADS
 * Description: Web-based Auto flow Documents System
 * Copyright: 2007
 * Company: CoE
 * @author: Mr.Nattasan Wang-Aphisit
 * @version 1.1
 */

package wads.drawing.node;

import wads.app.*;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.geom.Rectangle2D;
import javax.swing.ImageIcon;

public class DatabaseNode extends CaseNode {
//  private static final long serialVersionUID = 7589901459732210525L;
  
//  private Properties properties;
  transient private BaseWADDialog wNodeDialog;

  private ImageIcon icon = new ImageIcon("images/database.png");
//  public static final int DEFAULT_DB_ICON_WIDTH = 30;
//  public static final int DEFAULT_DB_ICON_HEIGHT = 30;
  private int gap = 10;


  public DatabaseNode(Point anchor) {
    super(anchor, "Database");

    id = ++idCount;
//    properties = new Properties();
//    super.initContent();

    setWidth(DEFAULT_NODE_ICON_WIDTH);
    setHeight(DEFAULT_NODE_ICON_HEIGHT);
  }

//  @Override
//  public CaseNodeDialog createDialog(){
//    return new CaseNodeDialog(this, panelNames);
//  }

  @Override
  protected void draw(Graphics2D g2d){
    //Init the big box dimension
    //int bigBoxWidth=0;
    //int bigBoxHeight=0;

    //Init small box height
    int smallBoxHeight = 15;
    //int smallBoxWidth = 40;

    //Init big box min height
    //int minBigBoxHeight = 30;

    //Init ascender line
    //int ascLineStartX = this.x + 2*this.gap;
    int ascLineStartY = getStartY() + smallBoxHeight + this.gap;

    //Get the text bounds
    //for (int i=0;i<this.contentCount;i++){
    g2d.setColor(Color.black);
    //Get bounds of the text
    // d[i] = getActualTextBounds(g2d,content[i]);

    drawTextAlign(g2d, "Documents Tray", ascLineStartY+10,this.gap);
    //}
    setNodeShapeBounds2D(getStartX(), getStartY(), CaseNode.DEFAULT_NODE_ICON_HEIGHT, CaseNode.DEFAULT_NODE_ICON_WIDTH);
    //g2d.drawRect(this.x, this.y, 20, 20);
    removeAllComponents();

    Rectangle2D box = new Rectangle2D.Float(getStartX(), getStartY(), CaseNode.DEFAULT_NODE_ICON_HEIGHT, CaseNode.DEFAULT_NODE_ICON_WIDTH);
    append(box);
    g2d.drawImage(icon.getImage(), getStartX(), getStartY(), DEFAULT_NODE_ICON_WIDTH, DEFAULT_NODE_ICON_HEIGHT, icon.getImageObserver());

    super.draw(g2d);
  }
  
  @Override
  public void showDialog(CaseEditor pf){
    wNodeDialog = new DatabaseNodeDialog(pf, this);
//    wNodeDialog.setProperties(this.properties);
    
    //Set the dialog of this DatabaseNode
    //nodeDialog is declared in CaseNode
    if(wNodeDialog != null && wNodeDialog instanceof BaseWADDialog){
      //init the displaying properties
//      wNodeDialog.setProperties(this.properties);
      wNodeDialog.initDisplay();
      wNodeDialog.setVisible(true);
    }
  }
}